package cc.orange.adapter;

import android.view.View;

import com.bumptech.glide.Glide;
import com.luck.picture.lib.adapter.holder.BasePreviewHolder;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.photoview.OnViewTapListener;

import androidx.annotation.NonNull;

/**
 * @author：luck
 * @date：2021/12/15 5:11 下午
 * @describe：PreviewImageHolder
 */
public class PrePicImageHolder extends BasePreviewHolder {

   public PrePicImageHolder(@NonNull View itemView) {
      super(itemView);
   }

   @Override
   protected void findViews(View itemView) {
   }

   @Override
   protected void loadImage(LocalMedia media, int maxWidth, int maxHeight) {
//        if (PictureSelectionConfig.imageEngine != null) {
      String availablePath = media.getAvailablePath();
//            if (maxWidth == PictureConfig.UNSET && maxHeight == PictureConfig.UNSET) {
//                PictureSelectionConfig.imageEngine.loadImage(itemView.getContext(), availablePath, coverImageView);
//            } else {
//                PictureSelectionConfig.imageEngine.loadImage(itemView.getContext(), coverImageView, availablePath, maxWidth, maxHeight);
//            }
//        }
      Glide.with(itemView.getContext()).load(availablePath).into(coverImageView);

   }

   @Override
   protected void onClickBackPressed() {
      coverImageView.setOnViewTapListener(new OnViewTapListener() {
         @Override
         public void onViewTap(View view, float x, float y) {
            if (mPreviewEventListener != null) {
               mPreviewEventListener.onBackPressed();
            }
         }
      });
   }

   @Override
   protected void onLongPressDownload(LocalMedia media) {
      coverImageView.setOnLongClickListener(new View.OnLongClickListener() {
         @Override
         public boolean onLongClick(View view) {
            if (mPreviewEventListener != null) {
               mPreviewEventListener.onLongPressDownload(media);
            }
            return false;
         }
      });
   }
}
